@@ -118,20 +118,22 @@ module Agents |
||
| 118 | 118 |
|
| 119 | 119 |
def check |
| 120 | 120 |
mqtt_client.connect do |c| |
| 121 |
- |
|
| 122 |
- Timeout::timeout((interpolated['max_read_time'].presence || 15).to_i) {
|
|
| 123 |
- c.get(interpolated['topic']) do |topic, message| |
|
| 124 |
- |
|
| 125 |
- # A lot of services generate JSON. Try that first |
|
| 126 |
- payload = JSON.parse(message) rescue message |
|
| 127 |
- |
|
| 128 |
- create_event :payload => {
|
|
| 129 |
- 'topic' => topic, |
|
| 130 |
- 'message' => payload, |
|
| 131 |
- 'time' => Time.now.to_i |
|
| 132 |
- } |
|
| 133 |
- end |
|
| 134 |
- } rescue TimeoutError |
|
| 121 |
+ begin |
|
| 122 |
+ Timeout.timeout((interpolated['max_read_time'].presence || 15).to_i) {
|
|
| 123 |
+ c.get(interpolated['topic']) do |topic, message| |
|
| 124 |
+ |
|
| 125 |
+ # A lot of services generate JSON. Try that first |
|
| 126 |
+ payload = JSON.parse(message) rescue message |
|
| 127 |
+ |
|
| 128 |
+ create_event :payload => {
|
|
| 129 |
+ 'topic' => topic, |
|
| 130 |
+ 'message' => payload, |
|
| 131 |
+ 'time' => Time.now.to_i |
|
| 132 |
+ } |
|
| 133 |
+ end |
|
| 134 |
+ } |
|
| 135 |
+ rescue Timeout::Error |
|
| 136 |
+ end |
|
| 135 | 137 |
|
| 136 | 138 |
c.disconnect |
| 137 | 139 |
end |